package com.ibeeking.found.file.rest.service.office.services;

import com.ibeeking.found.file.rest.service.office.entities.GroupEntity;
import com.ibeeking.found.file.rest.service.office.entities.PermissionEntity;
import com.ibeeking.found.file.rest.service.office.entities.UserEntity;
import com.ibeeking.found.file.rest.service.office.repositories.UserRepository;

import java.util.List;
import java.util.Optional;

//@Service
public class UserServices {
//    @Autowired
    private UserRepository userRepository;

//    @Autowired
    private GroupServices groupServices;

//    @Autowired
    private PermissionServices permissionService;

    // get a list of all users
    public List<UserEntity> findAll(){
//        return userRepository.findAll();
        return null;
    }

    // get a userEntity by their ID
    public Optional<UserEntity> findUserById(Integer id){
//        return userRepository.findById(id);
        return null;
    }

    // create a userEntity with the specified parameters
    public UserEntity createUser(String name, String email,
                                 List<String> description, String group,
                                 List<String> reviewGroups,
                                 List<String> viewGroups,
                                 List<String> editGroups,
                                 List<String> removeGroups,
                                 List<String> userInfoGroups, Boolean favoriteDoc,
                                 Boolean chat){
        UserEntity newUserEntity = new UserEntity();
        newUserEntity.setName(name);  // set the userEntity name
        newUserEntity.setEmail(email);  // set the userEntity email
//        newUserEntity.setGroup(groupServices.createGroup(group));  // set the userEntity group
        newUserEntity.setDescriptions(description);  // set the userEntity description
        newUserEntity.setFavorite(favoriteDoc);  // specify if the userEntity has the favorite documents or not

        List<GroupEntity> groupsReview = groupServices.createGroups(reviewGroups);  // define the groups whose changes the userEntity can accept/reject
        List<GroupEntity> commentGroupsView = groupServices.createGroups(viewGroups);  // defines the groups whose comments the userEntity can view
        List<GroupEntity> commentGroupsEdit = groupServices.createGroups(editGroups);  // defines the groups whose comments the userEntity can edit
        List<GroupEntity> commentGroupsRemove = groupServices.createGroups(removeGroups);  // defines the groups whose comments the userEntity can remove
        List<GroupEntity> usInfoGroupEntities = groupServices.createGroups(userInfoGroups);

        PermissionEntity permissionEntity = permissionService
                .createPermission(groupsReview, commentGroupsView, commentGroupsEdit, commentGroupsRemove, usInfoGroupEntities, chat);  // specify permissions for the current userEntity
        newUserEntity.setPermissions(permissionEntity);

//        userRepository.save(newUserEntity); // save a new userEntity

        return newUserEntity;
    }
}
